home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 424_01 / ed_157 / remove_win.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-13  |  4.4 KB  |  138 lines

  1. /*
  2.  * Copyright (C) 1992 by Rush Record (rhr@clio.rice.edu)
  3.  * 
  4.  * This file is part of ED.
  5.  * 
  6.  * ED is free software; you can redistribute it and/or modify it under the terms
  7.  * of the GNU General Public License as published by the Free Software Foundation.
  8.  * 
  9.  * ED is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  10.  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  11.  * PARTICULAR PURPOSE.  See the GNU General Public License for more details.
  12.  * 
  13.  * You should have received a copy of the GNU General Public License along with ED
  14.  * (see the file COPYING).  If not, write to the Free Software Foundation, 675
  15.  * Mass Ave, Cambridge, MA 02139, USA.
  16.  */
  17. #include "opsys.h"
  18.  
  19. #include <stdio.h>
  20.  
  21. #include "rec.h"
  22. #include "window.h"
  23. #include "ed_dec.h"
  24.  
  25. /******************************************************************************\
  26. |Routine: remove_window
  27. |Callby: wincom
  28. |Purpose: Removes a window from the screen. Throws away everything in the window.
  29. |Arguments:
  30. |    n is the number of the window to remove (zero-based).
  31. \******************************************************************************/
  32. void remove_window(n)
  33. Int n;
  34. {
  35.     Int i,central,oldbot,oldtop,oldwin;
  36.     rec_ptr r;
  37.  
  38.     oldwin = CURWINDOW;    /* save so we can move to correct window after all is done */
  39. #ifndef GNUDOS
  40.     update_bookmark(n);
  41. #endif
  42.     toss_data(WINDOW[n].base);    /* toss all the records, and the base pointer */
  43.     ifree(WINDOW[n].filename);    /* toss the file name buffer */
  44.     if(WINDOW[n].filebuf)
  45.         unmap_file(WINDOW[n].filebuf);
  46.     if(WINDOW[n].bookmark)
  47.         ifree(WINDOW[n].bookmark);    /* toss the bookmark file name buffer */
  48.     WINDOW[n].bookmark = NULL;
  49.     if(n == NWINDOWS - 1)    /* closing bottom window */
  50.     {
  51.         i = --NWINDOWS - 1;
  52.         oldbot = WINDOW[i].botrow;
  53.         WINDOW[i].botrow = NROW;
  54.         new_botrec(i);
  55.         calc_limits(WINDOW[i].toprow,WINDOW[i].botrow,&WINDOW[i].toplim,&WINDOW[i].botlim);
  56.         set_window(i);
  57.         paint(oldbot + 1,NROW,FIRSTCOL);
  58.         if(CURROW < TOPLIM)
  59.             CURROW += scroll_down(TOPLIM - CURROW);
  60.         fix_botrec();
  61.         save_window();
  62.     }
  63.     else
  64.     {
  65. /* closing an enclosed window */
  66.         central = (WINDOW[n].toprow + WINDOW[n].botrow) >> 1;    /* this becomes filename line of follower */
  67.         oldbot = WINDOW[n - 1].botrow;
  68.         WINDOW[n - 1].botrow = central - 1;
  69.         new_botrec(n - 1);
  70.         calc_limits(WINDOW[n - 1].toprow,WINDOW[n - 1].botrow,&WINDOW[n - 1].toplim,&WINDOW[n - 1].botlim);
  71.         set_window(n - 1);
  72.         paint(oldbot + 1,central - 1,FIRSTCOL);
  73.         if(CURROW < TOPLIM)
  74.             CURROW += scroll_down(TOPLIM - CURROW);
  75.         fix_botrec();
  76.         save_window();
  77. /* now expand the following window */
  78.         move(central,1);
  79.         ers_end();
  80.         reverse();
  81.         putz(WINDOW[n + 1].filename);
  82.         normal();
  83.         oldtop = WINDOW[n + 1].toprow;
  84.         WINDOW[n + 1].toprow = central + 1;
  85.         calc_limits(WINDOW[n + 1].toprow,WINDOW[n + 1].botrow,&WINDOW[n + 1].toplim,&WINDOW[n + 1].botlim);
  86. /* we have to be more careful when expanding upwards... */
  87.         r = WINDOW[n + 1].toprec;
  88.         for(i = oldtop;i > WINDOW[n + 1].toprow && r->prev != WINDOW[n + 1].base;i--,r = r->prev);
  89.         WINDOW[n + 1].toprec = r;
  90.         if(i == WINDOW[n + 1].toprow)    /* we were able to back up enough */
  91.         {
  92.             set_window(n + 1);
  93.             paint(central + 1,oldtop - 1,FIRSTCOL);
  94.         }
  95.         else    /* had to scroll some... */
  96.         {
  97.             new_botrec(n + 1);
  98.             set_window(n + 1);
  99.             paint(TOPROW,BOTROW,FIRSTCOL);
  100.             CURROW -= i - TOPROW;
  101.         }
  102.         if(CURROW > BOTLIM)
  103.             CURROW -= scroll_up(CURROW - BOTLIM);
  104.         fix_botrec();
  105.         save_window();
  106. /* move the window data structures around */
  107.         NWINDOWS--;
  108.         for(i = n;i < NWINDOWS;i++)
  109.         {
  110.             WINDOW[i].base = WINDOW[i + 1].base;
  111.             WINDOW[i].currec = WINDOW[i + 1].currec;
  112.             WINDOW[i].toprec = WINDOW[i + 1].toprec;
  113.             WINDOW[i].botrec = WINDOW[i + 1].botrec;
  114.             WINDOW[i].curbyt = WINDOW[i + 1].curbyt;
  115.             WINDOW[i].toprow = WINDOW[i + 1].toprow;
  116.             WINDOW[i].botrow = WINDOW[i + 1].botrow;
  117.             WINDOW[i].toplim = WINDOW[i + 1].toplim;
  118.             WINDOW[i].botlim = WINDOW[i + 1].botlim;
  119.             WINDOW[i].currow = WINDOW[i + 1].currow;
  120.             WINDOW[i].curcol = WINDOW[i + 1].curcol;
  121.             WINDOW[i].firstcol = WINDOW[i + 1].firstcol;
  122.             WINDOW[i].wantcol = WINDOW[i + 1].wantcol;
  123.             WINDOW[i].modified = WINDOW[i + 1].modified;
  124.             WINDOW[i].diredit = WINDOW[i + 1].diredit;
  125.             WINDOW[i].binary = WINDOW[i + 1].binary;
  126.             WINDOW[i].news = WINDOW[i + 1].news;
  127.             WINDOW[i].filebuf = WINDOW[i + 1].filebuf;
  128.             WINDOW[i].filename = WINDOW[i + 1].filename;
  129.             WINDOW[i].bookmark = WINDOW[i + 1].bookmark;
  130.         }
  131.     }
  132.     if(n <= oldwin)
  133.         oldwin--;
  134.     set_window(oldwin);
  135.     move(CURROW,CURCOL);
  136. }
  137.  
  138.